#!/bin/bash
#
# Prerequisition:
# kernel image: arch/arm/boot/zImage
# rootfs      : 
DIR=$(readlink -f $(dirname $0))
source $DIR/common.sh

IMG_PATH=$KERNEL_PATH/arch/arm/boot/zImage
ROOTFS_PATH=$BUSYBOX_PATH/$ROOTFS_FILE

if [ $# -eq 0 ]
then
	echo "Usage:  $DIR/$0 sd|ram"
	exit 1
fi
while [[ $# -gt 0 ]]
do
	key="$1"
	case $key in
		sd | ram )
			FILE_TYPE=$key
			;;
		*)
			echo "Unknown arguments:  $1"
			exit 1
			;;
	esac
	shift
done


pushd $DIR

[ -f $IMG_PATH ]  || { echo "$IMG_PATH not found!" && exit 1 ; }
[ -f $ROOTFS_PATH ] || { echo "$ROOTFS_PATH  not found!" && exit 1 ; }

case $FILE_TYPE in
	sd )
		qemu-system-arm -M $BOARD_TYPE -m 512M -kernel $IMG_PATH -nographic -append "root=/dev/mmcblk0 rw console=ttyAMA0"  -sd $ROOTFS_PATH
		;;
	ram )
		# -s shorthand for -gdb tcp::1234
		# -S freeze CPU at startup
		qemu-system-arm -M $BOARD_TYPE -m 512M -kernel $IMG_PATH -nographic -initrd $ROOTFS_PATH -append "root=/dev/ram rw rdinit=/sbin/init console=ttyAMA0"
		;;
esac
popd
